package com.hxkj.service.impl;

import com.hxkj.client.service.MessageSettingServiceClient;
import com.hxkj.domain.po.MessageSetting;
import com.hxkj.service.MessageSettingService;
import com.platform.common.domain.exception.CustomMessageException;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MessageSettingServiceImpl implements MessageSettingService{

    @Autowired
    private MessageSettingServiceClient msClient;

    @Override
    public void userMessageSetting(MessageSetting messageSetting) throws Exception {
        if(StringUtils.isBlank(messageSetting.getUserId())){
            throw new CustomMessageException("用户编号不能为空！");
        }
        ResultMessageStruct result = msClient.userMessageSetting(messageSetting);
        if(result.getCode() != 200){
            throw new CustomMessageException(result.getMessage());
        }
    }

    @Override
    public MessageSetting getMessageSetting(MessageSetting messageSetting) throws Exception {
        if(StringUtils.isBlank(messageSetting.getUserId())){
            throw new CustomMessageException("用户编号不能为空！");
        }
        ResultDataStruct<MessageSetting> result = msClient.getMessageSetting(messageSetting);
        if(result.getCode() != 200){
            throw new CustomMessageException(result.getMessage());
        }
        return result.getData();
    }
}
